package com.zft.userwalletmanager.application.service;


import com.zft.userwalletmanager.domain.bo.WalletBO;
import com.zft.userwalletmanager.infrastructure.gateway.database.dao.AccountFlowDAO;
import com.zft.userwalletmanager.infrastructure.gateway.database.dao.WalletDAO;
import com.zft.userwalletmanager.infrastructure.gateway.database.model.AccountFlowDO;
import com.zft.userwalletmanager.infrastructure.gateway.database.model.WalletDO;
import com.zft.userwalletmanager.web.request.WalletBalanceRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class WalletService {
    @Autowired
    private WalletDAO walletDAO;
    /**
     * 查询钱包余额
     * @param userId
     * @return
     */
    public WalletDO selectWalletByUserId(String userId,Boolean lock) {
        if (StringUtils.isBlank(userId)) {
            throw new IllegalArgumentException("WalletService||selectWalletByUserId||userId is null");
        }
        return walletDAO.selectWalletByUserId(userId,lock);
    }

    /**
     * 更新钱包余额
     * @param userId
     * @param newBalance
     * @return
     */
    public int updateWalletBalance(String userId,Long newBalance) {
        if (StringUtils.isBlank(userId)) {
            throw new IllegalArgumentException("WalletService||updateWalletBalance||userId is null");
        }
        if (Objects.isNull(newBalance)) {
            throw new IllegalArgumentException("WalletService||updateWalletBalance||newBalance is null");
        }
        return walletDAO.updateWalletBalance(userId,newBalance);
    }


}
